<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>ActiveMQ初见 | 坤个人博客</title><meta name="author" content="Houkl"><meta name="copyright" content="Houkl"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="简介：ActiveMQ是一个开源的、基于Java的消息队列系统。它实现了Java Message Service (JMS) API，并提供了可靠的、高性能的消息传递解决方案。ActiveMQ具有分布式、多协议支持、高可用性以及可扩展性等特点，使其成为构建可靠、弹性和可扩展的应用程序的理想选择。 ActiveMQ的使用方式1. 下载和安装ActiveMQ首先，您需要从 ActiveMQ官方网站下载">
<meta property="og:type" content="article">
<meta property="og:title" content="ActiveMQ初见">
<meta property="og:url" content="http://hkl.gitee.io/houkl/2018/11/05/middleware/activeMQ/index.html">
<meta property="og:site_name" content="坤个人博客">
<meta property="og:description" content="简介：ActiveMQ是一个开源的、基于Java的消息队列系统。它实现了Java Message Service (JMS) API，并提供了可靠的、高性能的消息传递解决方案。ActiveMQ具有分布式、多协议支持、高可用性以及可扩展性等特点，使其成为构建可靠、弹性和可扩展的应用程序的理想选择。 ActiveMQ的使用方式1. 下载和安装ActiveMQ首先，您需要从 ActiveMQ官方网站下载">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/06/06/pCPxUHg.png">
<meta property="article:published_time" content="2018-11-04T16:00:00.000Z">
<meta property="article:modified_time" content="2018-11-04T16:00:00.000Z">
<meta property="article:author" content="Houkl">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/06/06/pCPxUHg.png"><link rel="shortcut icon" href="/houkl/img/favicon.png"><link rel="canonical" href="http://hkl.gitee.io/houkl/2018/11/05/middleware/activeMQ/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/houkl/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/houkl/',
  algolia: undefined,
  localSearch: {"path":"/houkl/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'ActiveMQ初见',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2018-11-05 00:00:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = 'hidden';
    document.getElementById('loading-box').classList.remove("loaded")
  }
}

preloader.initLoading()
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s1.ax1x.com/2023/05/31/p9v6spQ.md.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/houkl/archives/"><div class="headline">文章</div><div class="length-num">21</div></a><a href="/houkl/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/houkl/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/06/06/pCPxUHg.png')"><nav id="nav"><span id="blog-info"><a href="/houkl/" title="坤个人博客"><span class="site-name">坤个人博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">ActiveMQ初见</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2018-11-04T16:00:00.000Z" title="发表于 2018-11-05 00:00:00">2018-11-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2018-11-04T16:00:00.000Z" title="更新于 2018-11-05 00:00:00">2018-11-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/houkl/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/">中间件</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="ActiveMQ初见"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="简介："><a href="#简介：" class="headerlink" title="简介："></a>简介：</h2><p>ActiveMQ是一个开源的、基于Java的消息队列系统。它实现了Java Message Service (JMS) API，并提供了可靠的、高性能的消息传递解决方案。ActiveMQ具有分布式、多协议支持、高可用性以及可扩展性等特点，使其成为构建可靠、弹性和可扩展的应用程序的理想选择。</p>
<h2 id="ActiveMQ的使用方式"><a href="#ActiveMQ的使用方式" class="headerlink" title="ActiveMQ的使用方式"></a>ActiveMQ的使用方式</h2><h3 id="1-下载和安装ActiveMQ"><a href="#1-下载和安装ActiveMQ" class="headerlink" title="1. 下载和安装ActiveMQ"></a>1. 下载和安装ActiveMQ</h3><p>首先，您需要从 <a target="_blank" rel="noopener" href="https://activemq.apache.org/" title="点击跳转">ActiveMQ官方网站</a>下载ActiveMQ的最新版本。然后按照官方文档提供的指南进行安装和配置。</p>
<h3 id="2-引入ActiveMQ的依赖"><a href="#2-引入ActiveMQ的依赖" class="headerlink" title="2. 引入ActiveMQ的依赖"></a>2. 引入ActiveMQ的依赖</h3><p>在您的Java项目中，需要引入ActiveMQ的相关依赖。如果使用Maven构建项目，可以在项目的pom.xml文件中添加以下依赖：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.activemq<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activemq-all<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>&#123;activemq-version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>请确保将<code>&#123;activemq-version&#125;</code>替换为您下载的ActiveMQ版本号。</p>
<h3 id="3-配置ActiveMQ连接"><a href="#3-配置ActiveMQ连接" class="headerlink" title="3. 配置ActiveMQ连接"></a>3. 配置ActiveMQ连接</h3><p>在您的应用程序中，需要配置连接到ActiveMQ的相关信息，例如URL、用户名和密码等。以下是一个示例的ActiveMQ连接配置：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ActiveMQConfig</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;activemq.broker-url&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String brokerUrl;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;activemq.username&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String username;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;activemq.password&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String password;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> ConnectionFactory <span class="title function_">connectionFactory</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="type">ActiveMQConnectionFactory</span> <span class="variable">connectionFactory</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ActiveMQConnectionFactory</span>();</span><br><span class="line">        connectionFactory.setBrokerURL(brokerUrl);</span><br><span class="line">        connectionFactory.setUserName(username);</span><br><span class="line">        connectionFactory.setPassword(password);</span><br><span class="line">        <span class="keyword">return</span> connectionFactory;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> JmsTemplate <span class="title function_">jmsTemplate</span><span class="params">(ConnectionFactory connectionFactory)</span> &#123;</span><br><span class="line">        <span class="type">JmsTemplate</span> <span class="variable">jmsTemplate</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">JmsTemplate</span>();</span><br><span class="line">        jmsTemplate.setConnectionFactory(connectionFactory);</span><br><span class="line">        <span class="keyword">return</span> jmsTemplate;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在上述代码中，我们使用Spring的<code>@Configuration</code>注解创建了一个配置类，定义了连接到ActiveMQ的相关信息。通过<code>@Value</code>注解，我们可以从配置文件中读取这些属性值。</p>
<h3 id="4-发送和接收消息"><a href="#4-发送和接收消息" class="headerlink" title="4. 发送和接收消息"></a>4. 发送和接收消息</h3><p>使用ActiveMQ发送和接收消息非常简单。以下是一个简单的示例：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MessageService</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> JmsTemplate jmsTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sendMessage</span><span class="params">(String destination, String message)</span> &#123;</span><br><span class="line">        jmsTemplate.convertAndSend(destination, message);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@JmsListener(destination = &quot;myQueue&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">receiveMessage</span><span class="params">(String message)</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;Received message: &quot;</span> + message);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在上述示例中，我们通过<code>JmsTemplate</code>实例将消息发送到指定的目的地，并使用<code>@JmsListener</code>注解接收来自目标队列的消息。</p>
<h2 id="ActiveMQ-如何实现消峰？"><a href="#ActiveMQ-如何实现消峰？" class="headerlink" title="ActiveMQ 如何实现消峰？"></a>ActiveMQ 如何实现消峰？</h2><p>在使用 ActiveMQ 进行消息传递时，消峰是一个重要的考虑因素。消峰是指在高峰期消息量激增时，保证消息队列的稳定性和可用性，避免队列积压或系统崩溃。下面是一些实现消峰的常用方法：</p>
<ol>
<li><strong>增加队列容量</strong>：通过增加消息队列的容量，可以处理更多的消息并缓解高峰期的压力。可以通过调整 ActiveMQ 的配置文件来增加队列容量。</li>
<li><strong>负载均衡</strong>：使用多个 ActiveMQ 实例并进行负载均衡，将消息分发到不同的实例上。这样可以分散高峰期的消息流量，提高整体系统的吞吐量。</li>
<li><strong>限流控制</strong>：通过限制消息的发送速率，控制消息的流量。可以设置消息发送的速率上限，避免瞬间发送大量消息导致队列积压。可以使用 ActiveMQ 提供的一些机制，如基于时间的发送间隔或基于消息数量的限制。</li>
<li><strong>延迟消费</strong>：将某些非紧急的消息延迟消费，优先处理重要和紧急的消息。可以通过设置消息的 TTL（Time-To-Live）或使用消息优先级来控制消息的消费顺序。</li>
<li><strong>消息分片</strong>：将消息分片处理，将大量消息分成多个小批量处理。可以将消息分配给多个消费者并行处理，提高处理效率。</li>
<li><strong>异步处理</strong>：将消息的处理异步化，通过使用线程池或消息驱动的方式来处理消息。这样可以减少消息发送者与接收者之间的耦合，提高系统的响应速度和并发处理能力。</li>
</ol>
<p>需要注意的是，消峰并非一种绝对的解决方案，而是根据具体情况选择合适的方法来应对高峰期的压力。根据业务需求和系统架构，可以结合使用上述方法或采用其他方法来实现消峰。</p>
<p>以下是一个使用 ActiveMQ 实现消峰的简单示例代码：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MessageService</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> JmsTemplate jmsTemplate;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">sendMessage</span><span class="params">(String destination, String message)</span> &#123;</span><br><span class="line">        jmsTemplate.convertAndSend(destination, message);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@JmsListener(destination = &quot;myQueue&quot;, concurrency = &quot;5-10&quot;)</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">receiveMessage</span><span class="params">(String message)</span> &#123;</span><br><span class="line">        <span class="comment">// 处理消息</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>在上述示例中，通过设置 <code>concurrency</code> 参数来控制消费者的并发数，从而实现消息的并发处理。</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>本文介绍了ActiveMQ的基本概念和使用方式。通过下载和安装ActiveMQ，引入相关依赖，配置连接信息，并使用<code>JmsTemplate</code>发送和接收消息，您可以轻松地集成ActiveMQ到您的应用程序中。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://hkl.gitee.io/houkl">Houkl</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://hkl.gitee.io/houkl/2018/11/05/middleware/activeMQ/">http://hkl.gitee.io/houkl/2018/11/05/middleware/activeMQ/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://hkl.gitee.io/houkl" target="_blank">坤个人博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/06/06/pCPxUHg.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/houkl/2018/12/15/java/synchronized/" title="深入了解 Java 中的 Synchronized 关键字"><img class="cover" src="https://s1.ax1x.com/2023/06/06/pCPzDde.png" onerror="onerror=null;src='/houkl/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">深入了解 Java 中的 Synchronized 关键字</div></div></a></div><div class="next-post pull-right"><a href="/houkl/2018/10/09/srping/springCloudsw/" title="实现分布式事务的艺术：Spring Cloud分布式事务解决方案"><img class="cover" src="https://s1.ax1x.com/2023/06/06/pCPb46e.png" onerror="onerror=null;src='/houkl/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">实现分布式事务的艺术：Spring Cloud分布式事务解决方案</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s1.ax1x.com/2023/05/31/p9v6spQ.md.jpg" onerror="this.onerror=null;this.src='/houkl/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Houkl</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/houkl/archives/"><div class="headline">文章</div><div class="length-num">21</div></a><a href="/houkl/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/houkl/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/houkunliang"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">个人博客不定期更新，还望各位看官谅解</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E4%BB%8B%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">简介：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ActiveMQ%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E5%BC%8F"><span class="toc-number">2.</span> <span class="toc-text">ActiveMQ的使用方式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E4%B8%8B%E8%BD%BD%E5%92%8C%E5%AE%89%E8%A3%85ActiveMQ"><span class="toc-number">2.1.</span> <span class="toc-text">1. 下载和安装ActiveMQ</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%BC%95%E5%85%A5ActiveMQ%E7%9A%84%E4%BE%9D%E8%B5%96"><span class="toc-number">2.2.</span> <span class="toc-text">2. 引入ActiveMQ的依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E9%85%8D%E7%BD%AEActiveMQ%E8%BF%9E%E6%8E%A5"><span class="toc-number">2.3.</span> <span class="toc-text">3. 配置ActiveMQ连接</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E5%8F%91%E9%80%81%E5%92%8C%E6%8E%A5%E6%94%B6%E6%B6%88%E6%81%AF"><span class="toc-number">2.4.</span> <span class="toc-text">4. 发送和接收消息</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ActiveMQ-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%B6%88%E5%B3%B0%EF%BC%9F"><span class="toc-number">3.</span> <span class="toc-text">ActiveMQ 如何实现消峰？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/06/28/java/volatile/" title="深入理解Java中的volatile关键字"><img src="https://s1.ax1x.com/2023/06/06/pCiS2tJ.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入理解Java中的volatile关键字"/></a><div class="content"><a class="title" href="/houkl/2019/06/28/java/volatile/" title="深入理解Java中的volatile关键字">深入理解Java中的volatile关键字</a><time datetime="2019-06-27T16:00:00.000Z" title="发表于 2019-06-28 00:00:00">2019-06-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/04/03/java/reentrantLock/" title="深入探索Java中的ReentrantLock"><img src="https://s1.ax1x.com/2023/06/06/pCiSafs.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入探索Java中的ReentrantLock"/></a><div class="content"><a class="title" href="/houkl/2019/04/03/java/reentrantLock/" title="深入探索Java中的ReentrantLock">深入探索Java中的ReentrantLock</a><time datetime="2019-04-02T16:00:00.000Z" title="发表于 2019-04-03 00:00:00">2019-04-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/01/26/java/rushToPurchase/" title="用Redis + Lua 实现商品抢购"><img src="https://s1.ax1x.com/2023/06/06/pCiSgk4.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="用Redis + Lua 实现商品抢购"/></a><div class="content"><a class="title" href="/houkl/2019/01/26/java/rushToPurchase/" title="用Redis + Lua 实现商品抢购">用Redis + Lua 实现商品抢购</a><time datetime="2019-01-25T16:00:00.000Z" title="发表于 2019-01-26 00:00:00">2019-01-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2018/12/15/java/synchronized/" title="深入了解 Java 中的 Synchronized 关键字"><img src="https://s1.ax1x.com/2023/06/06/pCPzDde.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入了解 Java 中的 Synchronized 关键字"/></a><div class="content"><a class="title" href="/houkl/2018/12/15/java/synchronized/" title="深入了解 Java 中的 Synchronized 关键字">深入了解 Java 中的 Synchronized 关键字</a><time datetime="2018-12-14T16:00:00.000Z" title="发表于 2018-12-15 00:00:00">2018-12-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2018/11/05/middleware/activeMQ/" title="ActiveMQ初见"><img src="https://s1.ax1x.com/2023/06/06/pCPxUHg.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="ActiveMQ初见"/></a><div class="content"><a class="title" href="/houkl/2018/11/05/middleware/activeMQ/" title="ActiveMQ初见">ActiveMQ初见</a><time datetime="2018-11-04T16:00:00.000Z" title="发表于 2018-11-05 00:00:00">2018-11-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Houkl</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/houkl/js/utils.js"></script><script src="/houkl/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/houkl/js/search/local-search.js"></script></div></div></body></html>